import TableExpression from "./expression/TableExpression";
import MetaData from "./expression/MetaData";
import Core from "./core/MysqlCore";
import MysqlConfig from "./config/MysqlConfig";
import ReadisConfig from "./config/ReadisConfig";
import TableQueryBuilder from "./core/TableQueryBuilder";

class index extends TableQueryBuilder{
    /**
     * 数据库字段规则
     */
    public sqlFieldRule: "bigHump" | "smallHump" | "underline" = "underline";
    /**
     * 程序字段规则
     */
    public codeFieldRule: "bigHump" | "smallHump" | "underline" = "smallHump";

    public core: Core;

    constructor(mysqlConfig?: MysqlConfig, redistConfig?: ReadisConfig) {
        super();
        this.core = new Core(mysqlConfig, redistConfig)
        this.core.connection();
    }

    /*** 设置回调钩子 */
    public setHook() {

    }

    /**
     * 选择需要操作的表
     */
    public table(name: string | ((table: TableQueryBuilder) => any), alias?: string): TableExpression;
    public table(name: ((table: TableQueryBuilder) => any), alias: string): TableExpression;
    public table(name: string | ((table: TableQueryBuilder) => any), alias: string = '') {
        return super.table.bind({meta:new MetaData(this.core, this.sqlFieldRule, this.codeFieldRule)})(name as string,alias)
    }

    public select(sql: string, parameter: any[] = []) {
        return super.select.bind({core:this.core,meta:new MetaData(this.core, this.sqlFieldRule, this.codeFieldRule)})(sql,parameter);
    }
}

export = new index();